package com.bw.liuyushan.zhuangao4_weektest2.Adapter;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * ZhuanGao4_WeekTest2
 * file name is : FragmentMainAdapter
 * created by Ender on 2021/8/23 9:07.
 * author : 刘雨杉
 * Describe(作用):
 */
public class FragmentMainAdapter extends FragmentStatePagerAdapter {
    ArrayList<Fragment> fragments;
//    private final HashMap<Integer,Fragment> hashMap;

    public FragmentMainAdapter(FragmentManager fm, ArrayList<Fragment> fragments) {
        super(fm);//BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        this.fragments = fragments;
//        hashMap=new HashMap<>();
    }

    @Override
    public Fragment getItem(int position) {
//        if (!hashMap.containsKey(position)){
//            hashMap.put(position,fragments.get(position));
//        }
//        return hashMap.get(position);
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

//    @Override
//    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//
//    }
}
